﻿var baseurl = "http://lvyougl.com";

(function (f, w) {

    if (w.tripstxt_COLLECT) {
        return
    }
    w.tripstxt_COLLECT = 1;
    var q = f.location,
		g = q.href,
		F = navigator.userAgent,
		C = w.body,
		t = C.parentNode,
		aq = false,
		af, ac, ab = F.indexOf("MSIE") >= 0 && F.indexOf("Opera") < 0,
		T = ab ? navigator.appVersion.split(";")[1].replace(/[ ]/g, "") : "",
		G = T == "MSIE6.0",
		E = T == "MSIE7.0",
		x = T == "MSIE8.0",
		ae = F.indexOf("Opera") >= 0 ? true : false,
		v;

    function p(i, b, d) {
        if (i.addEventListener) {
            i.addEventListener(b, d, false)
        } else {
            if (i.attachEvent) {
                i.attachEvent("on" + b, d)
            } else {
                i["on" + b] = d
            }
        }
    }
    function c(b) {
        return w.getElementById(b)
    }
    
    //获取选中内容
    function afterSelect() {
        var b = window,
			d = document;
        if (b.getSelection) {
            var range = window.getSelection().getRangeAt(0);
            var container = document.createElement('div');
            container.appendChild(range.cloneContents());
            return container.innerHTML;
        } else {
            if (d.getSelection) {
                var range = document.getSelection().getRangeAt(0);
                var container = document.createElement('div');
                container.appendChild(range.cloneContents());
                return container.innerHTML;
            } else {
                if (d.selection) {
                    return d.selection.createRange().innerHTML;
                }
            }
        }
    }

	function mouseCoords(ev) {
		if (ev.pageX || ev.pageY) {
			return { x: ev.pageX, y: ev.pageY };
		}
		return {
			x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y: ev.clientY + document.body.scrollTop - document.body.clientTop
		};
	}

    function a(i, d) {
        var b = c(i);
        if (!b || b.tagName.toLowerCase() !== "style") {
            b = w.createElement("style");
            b.id = i;
            if (ab) {
                b.type = "text/css";
                b.styleSheet.cssText = d;
                w.getElementsByTagName("head")[0].appendChild(b)
            } else {
                if ((F.lastIndexOf("Safari/") > 0) && parseInt(F.substr(F.lastIndexOf("Safari/") + 7, 7)) < 533) {
                    b.innerText = d;
                    C.appendChild(b)
                } else {
                    b.innerHTML = d;
                    C.appendChild(b)
                }
            }
        }
    }
    function V() {
        var L = [],
			D = document.body.getElementsByTagName("p"); //get p
        if (D.length <= 0) {
            alert("本页面没有适合的内容，请换一个页面试试吧~");
            return [];
        }
        for (var i = 0; i < D.length; i++) {
            if (D[i].innerHTML != null) {
                var b = clearHtml(D[i].innerHTML);
                L.push(b)
            }
        }
        if (L.length) {
            return L
        } else {
            return []
        }
    }

    function clearHtml(html)
    {
        var b = html.replace(/<img(.*?)>/g, function (m, e1) {
            return "[img " + e1 + "]";
        });
        b = b.replace(/<(.*?)>/g, function (m, e1) {
            return "";
        });
        b = b.replace(/\[img(.*?)\]/g, function (m, e1) {
            return "<img " + e1 + ">";
        });
        return b;
    }
    
    //判断是否允许本站抓去
    function ag() {
        var b = [
			[/^https?:\/\/.*?\.?lvyougl\.com\//, "很抱歉，不能抓取本站的内容噢，请到其他网站抓取吧~"],
			[/^file/, "本地内容是不能抓取的，去网页上抓取图片吧~"]
        ];
        for (var d = 0; d < b.length; d++) {
            if (b[d][0].test(g)) {
                alert(b[d][1]);
                return false
            }
        }
        return true
    }
    if (!ag()) {
        aq = true;
        w.tripstxt_COLLECT = 0;
        return
    }
    
    if (w.tripstxtCollectConfig && !w.tripstxtCollectConfig.autoExecute) {
        var at = " #tripstxt_dirpic_btn:link,#tripstxt_dirpic_btn:visited{position:absolute;z-index:500;width:120px;height:20px;overflow:hidden;padding:0 8px;border:1px solid #bababa;border-radius:5px;text-align:center;font:normal normal 12px/19px '\5FAE\8F6F\96C5\9ED1';color:#666;background:#fff;text-decoration:none;width:auto;height:30px;_width:120px;_height:26px;padding:0;border:0 none;text-indent:-9999px;background-color:transparent;background:url(" + baseurl + "/css/images/collect-tripstxt.png)-20px -60px;_background:url(" + baseurl + "/css/images/collect-tripstxt.png)-20px  -60px;background-repeat:no-repeat;} #tripstxt_dirpic_btn:hover{color:#999;text-decoration:none;background-position:0 -36px;} #tripstxt_dirpic_btn:focus{outline:0} ";
        a("tripstxtSHEET", at);
        return
    }
    var Y = V();
    if (Y.length <= 0) {
        alert("本页面没有适合的内容，请换一个页面试试吧~");
        w.tripstxt_COLLECT = 0;
        return
    }
    function Z() {
        var i, b, d, A, z = w.documentElement;
        if (f.innerHeight && f.scrollMaxY) {
            i = C.scrollWidth;
            b = f.innerHeight + f.scrollMaxY
        } else {
            if (C.scrollHeight > C.offsetHeight) {
                i = C.scrollWidth;
                b = C.scrollHeight
            } else {
                i = C.offsetWidth;
                b = C.offsetHeight
            }
        }
        if (self.innerHeight) {
            d = self.innerWidth;
            A = self.innerHeight
        } else {
            if (z && z.clientHeight) {
                d = z.clientWidth;
                A = z.clientHeight
            } else {
                if (C) {
                    d = C.clientWidth;
                    A = C.clientHeight
                }
            }
        }
        if (b < A) {
            pageHeight = A;
            y = pageHeight
        } else {
            pageHeight = b;
            y = pageHeight
        }
        if (i < d) {
            pageWidth = d
        } else {
            pageWidth = i
        }
        return [pageWidth, pageHeight, d, A]
    }
    function ar() {
        var b = av.parentNode;
        if (!b) {
            return
        }
        b.removeChild(av);
        b.removeChild(am);
        w.tripstxt_COLLECT = 0;
        if (!G) {
            C.style.paddingRight = N;
            t.style.overflowX = ad;
            t.style.overflowY = aa;
            C.style.overflowX = al;
            C.style.overflowY = ak
        }
        return false
    }

    document.onmouseup = function (e) {
        var abutton;
        var html = afterSelect();
        var selectdiv = "tripstxt_collectionword_select_div";
        var btn01 = "tripstxt_collectionword_select_btn01";
        if (html != undefined && html != "") {
            if (document.getElementById(selectdiv)) {
                abutton = document.getElementById(selectdiv);
                abutton.removeAttribute("style");
            } else {
                abutton = document.createElement("div");
                abutton.className = "tripstxt_zhai_icon";
                abutton.id = selectdiv;
                abutton.innerHTML = '<a class="tripstxt_zhai_btn"></a> ';
                var ul = document.createElement("ul");
                ul.className = "tripstxt_zhai_list";
                ul.setAttribute("style", "display:none");
                var li1 = document.createElement("li");
                li1.className = "tripstxt_zhai_li";
                li1.innerText = "仅采摘图";
                li1.onclick = function () {
                    var imgs = html.match(/<img(.*?)>/g);
                    if (imgs==null||imgs.length == 0) { alert("没有选中任何图片内容!"); } else {
                        var form = document.createElement("form");
                        form.setAttribute("action", baseurl + "/Tool/Collect/Images");
                        form.setAttribute("target", "tripstxt");
                        form.setAttribute("method", "post");
                        var tbody = document.createElement("textarea");
                        tbody.setAttribute("name", "body");
                        tbody.value = clearHtml(imgs.join("|"));
                        form.appendChild(tbody);
                        document.charset = "utf-8";
                        form.submit();
                        document.body.removeChild(abutton);
                    }
                }
                ul.appendChild(li1);
                var li1 = document.createElement("li");
                li1.className = "tripstxt_zhai_li";
                li1.innerText = "采摘到游记";
                li1.onclick = function () {
                    var form = document.createElement("form");
                    form.setAttribute("action", baseurl + "/Tool/Notes");
                    form.setAttribute("target", "tripstxt");
                    form.setAttribute("method", "post");
                    var tbody = document.createElement("textarea");
                    tbody.setAttribute("name", "txtbody");
                    tbody.value = clearHtml(html);
                    form.appendChild(tbody);
                    document.charset = "utf-8";
                    form.submit();
                    document.body.removeChild(abutton);
                }
                ul.appendChild(li1);
                abutton.appendChild(ul);
                document.body.appendChild(abutton);
            }
            var mousePosition = mouseCoords(e);
            abutton.setAttribute("style", "top:" + mousePosition.y + "px;left:" + mousePosition.x + "px;position:absolute;z-index:500;");
            abutton.onmouseover = function () {
                var btns = document.getElementsByClassName("tripstxt_zhai_list");
                btns[0].setAttribute("style", "display:initial")
            };
            abutton.onmouseout = function () {
                var btns = document.getElementsByClassName("tripstxt_zhai_list");
                btns[0].setAttribute("style", "display:none")
            };
        } else {
            abutton = document.getElementById(selectdiv);
            if (abutton && e.toElement.className != "tripstxt_zhai_li") {
                document.body.removeChild(abutton);
            }
        }
    }
    var aB ,
            r ,
            aC ,
            u ,
            aD ,
            s,
            ah ,
            at ,o ,
            ax ,
            av,
            am ,
            aA,
            O,N;
    function docollect() {
        aB = "tripstxt_",
        r = "#" + aB + "main",
        aC = "background",
        u = "position:relative",
        aD = aC + "-color:",
        s = "url(" + baseurl + "/css/images/collout-close.png)",
        ah = "z-index:90000000",
        at = [" #", aB, "mask{position:fixed;", ah, "0;top:0;right:0;bottom:0;left:0;", aD, " #000;opacity:.7;filter:alpha(opacity=70);} ", r, "{position: absolute;width:100%;line-height:1.2;padding:0;", ah, "1;top:0;left:0;", aD, "transparent;} #", aB, "container{zoom:1;width:904px;margin:0 auto;padding-bottom:24px;color:#666;background-color: rgba(255, 255, 255, 0.96)} #", aB, "container:after{content:'\\0020';display:block;height:0;overflow:hidden;clear:both;} #", aB, "panel{", u, ";float:right;", ah, "4;height:0px;width:0px;} #", aB, "panel a:link,#", aB, "panel a:visited{position:fixed;_position:absolute;top:12px;right:30px;_right:12px;width:80px;height:80px;padding:0;margin:0;", aD, "transparent;", aC, "-image:", s, "} #", aB, "panel a:hover{", aC, "-position:0 -80px} ", r, " .", aB, "unit{", u, ";float:left;+display:inline;padding:0;margin:0;margin:24px 12px 0;", ah, "2;border:1px solid #e7e7e7;text-align: center;", aD, "#fff;} ", r, " .", aB, "unit .tpmImg{", u, ";width:100%;height:100%;margin:0;padding:0;} ", r, " .", aB, "unit a{display:block;margin:0;padding:0;text-align:center;", aC, ":none !important} ", r, " .", aB, "unit img{display:block;padding:0;margin:0 auto;border:0 none;vertical-align:top;} ", r, " .", aB, "unit a *{cursor:pointer} ", r, " .", aB, "unit_sm,", r, " .", aB, "unit_sm a{width:150px;height:150px;} ", r, " .", aB, "dimen{position: absolute;height: 21px;line-height: 21px;right:-20px;top: -1px;width:19px;margin:-16px auto 0;padding:0 2px 1px;text-align:center;font-size:10px;font-family:tahoma,arial,sans-serif;", ah, "3;opacity:.9;filter:alpha(opacity=90);border-radius:3px;color:#fff;background-image: url(" + baseurl + "/css/images/close_c.png);background-color: #333;cursor: pointer;} ", r, " .", aB, "cover{position:absolute;width:200px;height:200px;top:0;left:0;", aD, "#000;opacity:.15;filter:alpha(opacity=15);display:none} ", r, " .", aB, "cross{position:absolute;width:100px;height:59px;line-height:16px;padding:41px 0 0;top:50px;left:50px;", aC, ":", s, " no-repeat 0 -160px;border:0 none;} ", r, " .", aB, "action:link .", aB, "cross,", r, " .", aB, "action:visited .", aB, "cross{display:none;} ", r, " .", aB, "action:hover .", aB, "cross,", r, " .", aB, "action:hover .", aB, "cover{display:block;} ", r, " .", aB, "unit_sm .", aB, "cross{top:25px;left:25px;} ", r, " .", aB, "seper{float:left;border-top:1px solid #eaeaea;padding:24px 0 0;margin:24px 0 0;color:#ebebeb;font:normal 16px/20px tahoma;} ", r, " img{margin:0 auto} #tripstxt_dirpic_btn:link,#tripstxt_dirpic_btn:visited{position:absolute;z-index:999999998;width:120px;height:20px;padding:0 8px;border:1px solid #bababa;border-radius:5px;text-align:center;font:normal normal 12px/19px '\5FAE\8F6F\96C5\9ED1';color:#666;background:#fff;text-decoration:none;width:102px;height:30px;_width:100px;_height:26px;padding:0;border:0 none;text-indent:-9999px;background-color:transparent;background:url(" + baseurl + "/css/images/collect-tripstxt.png)-20px -60px ;_background:url(" + baseurl + "/css/images/collect-tripstxt.png) -20px -60px;background-repeat:no-repeat;} #tripstxt_dirpic_btn:hover{color:#999;text-decoration:none;} #tripstxt_dirpic_btn:focus{outline:0} "].join(""),
        o = Z(),
        ax = (o[0] - 904) / 2,
        av = w.createElement("div"),
        am = w.createElement("div"),
        aA = w.createElement("div"),
        O = w.createElement("div");

        at += "#tripstxt_main{width:auto}#tripstxt_main .tripstxt_seper{margin-left:-" + ax + "px;padding-left:" + (ax + 12) + "px}";
        at += ".tripstxt_text_btn{background: url(" + baseurl + "/css/images/collectshouming_10.png) no-repeat -5px -3px; width:188px; height:45px; margin:0 auto;text-align:center;cursor:pointer;font-size:18px; color:#FFF; line-height:40px }.tripstxt_zhai_text{width:900px; margin:0 auto}.tripstxt_zhai_text li{ line-height:20px; border-bottom:1px #ddd dotted; padding:10px 0; margin:0px 15px;list-style: none;}.tripstxt_zhai_text li span{float:right;color:#bbb; background:url(" + baseurl + "/css/images/selecetedcityclose.png) no-repeat; display:block; width:14px; height:14px; margin-top:3px;cursor:pointer;}.tripstxt_zhai_text_list{height:500px; margin:15px 0; overflow-y:scroll;}.tripstxt_zhai_icon a{cursor:pointer; display:block; color:#666}.tripstxt_zhai_icon a:hover{text-decoration:none}.tripstxt_zhai_icon{position:relative; width:220px}.tripstxt_zhai_icon .tripstxt_zhai_btn{width:70px; height:36px; background:url(" + baseurl + "/css/images/zhai_icon.png) no-repeat; position:absolute; top:0; left:0}.tripstxt_zhai_icon .tripstxt_zhai_btn:hover{background-position: 0 -36px}.tripstxt_zhai_icon .tripstxt_zhai_list{position:absolute; top:0; left:68px; width:142px; height:62px; padding:3px; background:url(" + baseurl + "/css/images/zhai_icon.png) no-repeat -103px 0}.tripstxt_zhai_icon .tripstxt_zhai_list li{text-align:center; font-size:16px; height:30px; line-height:30px;list-style: none; cursor:pointer;}.tripstxt_zhai_icon .tripstxt_zhai_list li:hover{background:#e3346d; color:#FFF; border:1px #FFF solid}";
        if (G) {
            at += "#tripstxt_mask{position:absolute;height:" + o[1] + "px;}"
        }
        a("zdytripstxt", at);
        av.setAttribute("id", "tripstxt_mask");
        p(av, "click", ar);
        C.appendChild(av);
        if (w.defaultView) {
            N = w.defaultView.getComputedStyle(C).paddingRight,
                ad = w.defaultView.getComputedStyle(t).overflowX,
                aa = w.defaultView.getComputedStyle(t).overflowY,
                al = w.defaultView.getComputedStyle(C).overflowX,
                ak = w.defaultView.getComputedStyle(C).overflowY
        } else {
            if (t.currentStyle) {
                N = C.currentStyle.paddingRight,
                    ad = t.currentStyle.overflowX,
                    aa = t.currentStyle.overflowY,
                    al = C.currentStyle.overflowX,
                    ak = C.currentStyle.overflowY
            }
        }
        if (!G) {
            var S = am.style;
            C.style.paddingRight = "17px";
            C.style.overflowY = C.style.overflowX = S.overflowX = "hidden";
            if (ab || ae) {
                t.style.overflowY = t.style.overflowX = "hidden"
            }
            S.overflowY = "scroll";
            S.top = Math.max(C.scrollTop || 0, w.documentElement.scrollTop || 0) + "px";
            S.width = (o[0] + (E ? 17 : x ? 17 : 0)) + "px";
            S.height = o[3] + "px";
        }
        am.setAttribute("id", "tripstxt_main");

        C.appendChild(am);
        aA.setAttribute("id", "tripstxt_container");
        am.appendChild(aA);
        var h = {},
            ap = '<div class="tripstxt_zhai_text" ><form id="tripstxt_collect" action="' + baseurl + '/Tool/Collect/Article"target="tripstxt" method="post" ><ul class="tripstxt_zhai_text_list" style="height:' + parseInt(o[3] - 100) + 'px;">',
            aw = "",
            I = 0,
            aj = 0;
        for (var ay = 0; ay < Y.length; ay++) {
            if (Y[ay].length > 0) {
                ap += '<li><span class="tripstxt_dimen_close"></span>' + Y[ay] + '<textarea name="txtbody" style="display:none;">' + Y[ay] + '</textarea></li>'
                if (aj) {
                    aj = ""
                }
            }
        }
        ap += '</ul><div>指定类型<select id="selfmtx_collect_type"><option value="0" >id</option><option value="1" >class</option></select>:<input id="txtfmtx_collect_tagclass" type="txt"/><input type="button" id="btnfmtx_collect_ag" value="拾取"/><div id="submittripstxtcollectbtn" class="tripstxt_text_btn"><a>采集到攻略</a></div></div></form>';
        aA.innerHTML = ap;
        O.id = "tripstxt_panel";
        O.innerHTML = '<a id="tripstxt_closelink" href="javascript:;" target="_self" title="关闭"><button id="tripstxt_closebtn" style="display:none"></button></a>';
        am.insertBefore(O, aA);
        c("tripstxt_closelink").onclick = ar;
        c("tripstxt_closebtn").onclick = ar
        var liNodes = document.getElementsByClassName("tripstxt_dimen_close");
        for (var i = 0; i < liNodes.length; i++) {
            liNodes[i].onclick = function () {
                this.parentNode.parentNode.removeChild(this.parentNode);
            };
        }
        c("submittripstxtcollectbtn").onclick = dosubmittripstxtcollect;//btnfmtx_collect_ag
        c("btnfmtx_collect_ag").onclick = tryagenfmtxcollect;
    }
    function dosubmittripstxtcollect() {
        document.charset = "utf-8";
        c("tripstxt_collect").submit();
        ar();
    }
    function tryagenfmtxcollect()
    {
        var L = [],
			D=new Array();
        var type = document.getElementById("selfmtx_collect_type").value;
        if (type == 0) {
           var valbyid = document.getElementById(document.getElementById("txtfmtx_collect_tagclass").value);
           D.push(valbyid);
        } else {
            D = document.body.getElementsByClassName(document.getElementById("txtfmtx_collect_tagclass").value);
        }
        if (D==null||D.length <= 0) {
            alert("什么也没捞到！");
            return;
        }
        for (var i = 0; i < D.length; i++) {
            if (D[i].innerHTML != null) {
                var b = clearHtml(D[i].innerHTML);
                L.push(b)
            }
        }
        if (L.length) {
            Y = L;
            ar();
            docollect();
        }
        else {
            alert("什么也没捞到！");
            return;
        }
    }
    docollect();
})(window, document);
